﻿<Window x:Class="Converters.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:clr="clr-namespace:System;assembly=mscorlib"
    xmlns:local="clr-namespace:Converters"
    xmlns:f="clr-namespace:DotNetZen.Presentation.Converters;assembly=DotNetZen.Presentation.Converters"
    Title="Window1" Height="300" Width="300">
	<Window.Resources>
		<!-- Converters -->
		<local:StringFormatConverter x:Key="stringFormatConverter" />
		<local:TranslationConverter x:Key="translationConverter" />
		<local:SpeedConverter x:Key="speedConverter" />
		
		<!-- Enum binding sources -->
		<ObjectDataProvider MethodName="GetValues"
			ObjectType="{x:Type clr:Enum}"
			x:Key="languageOptions">
			<ObjectDataProvider.MethodParameters>
				<x:Type TypeName="local:Language" />
			</ObjectDataProvider.MethodParameters>
		</ObjectDataProvider>
		<ObjectDataProvider MethodName="GetValues"
			ObjectType="{x:Type clr:Enum}"
			x:Key="distanceOptions">
			<ObjectDataProvider.MethodParameters>
				<x:Type TypeName="local:Distance" />
			</ObjectDataProvider.MethodParameters>
		</ObjectDataProvider>
		<ObjectDataProvider MethodName="GetValues"
			ObjectType="{x:Type clr:Enum}"
			x:Key="timeOptions">
			<ObjectDataProvider.MethodParameters>
				<x:Type TypeName="local:Time" />
			</ObjectDataProvider.MethodParameters>
		</ObjectDataProvider>
	</Window.Resources>
	<StackPanel Orientation="Vertical">
		<DockPanel LastChildFill="True">
			<ComboBox x:Name="language" ItemsSource="{Binding Source={StaticResource languageOptions}}" Width="87" DockPanel.Dock="Left" />
			<ComboBox x:Name="distance" ItemsSource="{Binding Source={StaticResource distanceOptions}}" Width="77" DockPanel.Dock="Left" />
			<ComboBox x:Name="time" ItemsSource="{Binding Source={StaticResource timeOptions}}" Width="82" DockPanel.Dock="Left" />
			<TextBox x:Name="speed">60</TextBox>
		</DockPanel>
		<TextBlock>
			<TextBlock.Text>
				<MultiBinding Mode="OneWay">
					<MultiBinding.Converter>
						<f:MultiBindingFoldingConverter>
							<f:Fold Converter="{StaticResource stringFormatConverter}">
								<!-- Format -->
								<f:BindingReference Index="0"
									Converter="{StaticResource translationConverter}"
									ConverterParameter="Format" />
								<!-- "Speed" -->
								<f:BindingReference Index="0"
									Converter="{StaticResource translationConverter}"
									ConverterParameter="Speed" />
								<!-- Speed value -->
								<f:Fold
									Converter="{StaticResource speedConverter}">
									<!-- Speed -->
									<f:BindingReference Index="1" />
									<!-- Distance -->
									<f:BindingReference Index="2" />
									<!-- Time -->
									<f:BindingReference Index="3" />
								</f:Fold>
								<!-- Distance -->
								<f:Fold
									Converter="{StaticResource translationConverter}">
									<f:BindingReference Index="0" />
									<f:BindingReference Index="2" />
								</f:Fold>
								<!-- Time -->
								<f:Fold
									Converter="{StaticResource translationConverter}">
									<f:BindingReference Index="0" />
									<f:BindingReference Index="3" />
								</f:Fold>
							</f:Fold>
						</f:MultiBindingFoldingConverter>
					</MultiBinding.Converter>
					<!-- Language -->
					<Binding ElementName="language" Path="SelectedItem" />
					<!-- Speed -->
					<Binding ElementName="speed" Path="Text" />
					<!-- Distance -->
					<Binding ElementName="distance" Path="SelectedItem" />
					<!-- Time -->
					<Binding ElementName="time" Path="SelectedItem" />
				</MultiBinding>
			</TextBlock.Text>
		</TextBlock>
	</StackPanel>
</Window>
